
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */


final class ViewPendingCreditOrderSummary extends javax.swing.JInternalFrame {

    Object[][] tableObject=new Object[][]{};
    Systems systems=new Systems();
    Thread processThread=new Thread();
    Thread titleThread=new Thread();
    /** Creates new form ViewCredit */
    /** Creates new form ViewCredit */
    public ViewPendingCreditOrderSummary() {
        initComponents();
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Order Code", "Total Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            refreshTable();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jSumTextField = new javax.swing.JTextField();
        jPreviewReceiptButton = new javax.swing.JButton();
        jPrintReceiptButton = new javax.swing.JButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(ViewPendingCreditOrderSummary.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Order Code", "Total Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTable1MousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTable1MouseReleased(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTable1KeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(10);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N

        jRefreshButton.setFont(resourceMap.getFont("jRefreshButton.font")); // NOI18N
        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setFont(resourceMap.getFont("jCancelButton.font")); // NOI18N
        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jSumTextField.setText(resourceMap.getString("jSumTextField.text")); // NOI18N
        jSumTextField.setEnabled(false);
        jSumTextField.setName("jSumTextField"); // NOI18N

        jPreviewReceiptButton.setText(resourceMap.getString("jPreviewReceiptButton.text")); // NOI18N
        jPreviewReceiptButton.setName("jPreviewReceiptButton"); // NOI18N
        jPreviewReceiptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPreviewReceiptButtonActionPerformed(evt);
            }
        });

        jPrintReceiptButton.setText(resourceMap.getString("jPrintReceiptButton.text")); // NOI18N
        jPrintReceiptButton.setName("jPrintReceiptButton"); // NOI18N
        jPrintReceiptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPrintReceiptButtonActionPerformed(evt);
            }
        });

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N

        jCheckBox2.setText(resourceMap.getString("jCheckBox2.text")); // NOI18N
        jCheckBox2.setName("jCheckBox2"); // NOI18N

        jCheckBox5.setText(resourceMap.getString("jCheckBox5.text")); // NOI18N
        jCheckBox5.setName("jCheckBox5"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 830, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSumTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE)
                .addComponent(jPrintReceiptButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPreviewReceiptButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRefreshButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCancelButton)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox1)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox2)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox5)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jSumTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPreviewReceiptButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPrintReceiptButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox5))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed

        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            refreshTable();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }//GEN-LAST:event_jRefreshButtonActionPerformed

    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        
        if(processThread.isAlive())
        {
            try{
                processThread.stop();
                titleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. View Pending Credit Order Summary");
            enableControls();
        }
        else
        dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed

    public void print()
    {
        try
        {
            jTable1.print();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    private void jPreviewReceiptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPreviewReceiptButtonActionPerformed

        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            previewReceiptButtonClicked();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }//GEN-LAST:event_jPreviewReceiptButtonActionPerformed
    private void previewReceiptButtonClicked()
    {
        if(jTable1.getSelectedRow()==-1)
        {
            javax.swing.JOptionPane.showMessageDialog(javax.swing.JOptionPane.getRootFrame(),"Please Select An Order !","Allocation ERROR !",javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            int row=jTable1.getSelectedRow();
            String orderCode=jTable1.getValueAt(row,0).toString();
            String transferState="";
            String transferValue=systems.getValue(OpenMSApp.Database_A,"Select * from creditOrder where cCreditOrderCode='"+orderCode+"'","cActivity");
            int quantity=1;
            if(transferValue.trim().equalsIgnoreCase("Transfer Activity"))
            {
                transferState="Transfer";
            }
            java.lang.Runtime run=java.lang.Runtime.getRuntime();
            java.lang.Runtime runAgain=java.lang.Runtime.getRuntime();
            try
            {
                NoteWriter note=new NoteWriter();
                note.writeReceipt(orderCode,transferState,quantity);
                           
            if(OpenMSApp.d==null)
            {
                OpenMSApp.d=new NoteViewer("Preview Receipt - "+orderCode,Configuration.officialReceiptURLPath);
                OpenMSApp.d.setVisible(true);
            }
            else if(OpenMSApp.d.isVisible()==false)
            {
                OpenMSApp.d=new NoteViewer("Preview Receipt - "+orderCode,Configuration.officialReceiptURLPath);
                OpenMSApp.d.setVisible(true);         
            }
            else{
                OpenMSApp.d.setTitle("Preview Receipt - "+orderCode);
                OpenMSApp.d.doTas(1);
                OpenMSApp.d.transferFocus();
                
            }
                /*
                //run.exec("explorer C:\\Milliscript_MoneySpinner\\Note\\OfficialReceipt.htm");
                run.exec("explorer "+Configuration.officialReceiptPath);
                if(jCheckBox2.isSelected()){
                //run.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\"C:\\Milliscript_MoneySpinner\\Note\\OfficialReceipt.htm\" ");
                run.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\""+Configuration.officialReceiptPath+"\" ");
                    if(jCheckBox1.isSelected()){
                        runAgain.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\""+Configuration.officialReceiptPath+"\" ");
                    }
                }*/
                //printReceipt.setSelected(true);
            }
            catch(Exception e)
            {
                System.out.println("Error while adding edit employee ! "+e);
            }
        }
        refreshTable();        
    }
    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("mr no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+"first indices="+x[y]);
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+" curr indices="+x[y]);
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1KeyPressed

    private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("mr no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+"first indices="+x[y]);
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+" curr indices="+x[y]);
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1KeyReleased

    private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("mr no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+"first indices="+x[y]);
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+" curr indices="+x[y]);
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1MousePressed

    private void jTable1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseReleased
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("mr no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+"first indices="+x[y]);
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+" curr indices="+x[y]);
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1MouseReleased

    private void jPrintReceiptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPrintReceiptButtonActionPerformed

        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            printDoc();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }//GEN-LAST:event_jPrintReceiptButtonActionPerformed
    public void printDoc()
    {
        if(jTable1.getSelectedRow()==-1)
        {
            javax.swing.JOptionPane.showMessageDialog(javax.swing.JOptionPane.getRootFrame(),"Please Select An Order !","Allocation ERROR !",javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            int row=jTable1.getSelectedRow();
            String orderCode=jTable1.getValueAt(row,0).toString();
            String transferState="";
            String transferValue=systems.getValue(OpenMSApp.Database_A,"Select * from creditOrder where cCreditOrderCode='"+orderCode+"'","cActivity");
            int quantity=1;
        if(transferValue.trim().equalsIgnoreCase("Transfer Activity"))
        {
            transferState="Transfer";
        }        
        if(jCheckBox5.isSelected())
        {
            boolean found=false;
            javax.swing.JInternalFrame allIntFr[]=this.getDesktopPane().getAllFrames();
            for(javax.swing.JInternalFrame iFr:allIntFr)
            {
                if(iFr.getTitle().equalsIgnoreCase("::. Preview POS Receipt"))
                {
                    ((POSPrint)iFr).setReceiptValue(orderCode);
                    found=true;
                }
            }
            if(found==false)
                this.getDesktopPane().add(new POSPrint(orderCode));
            return;
        }
        java.lang.Runtime run=java.lang.Runtime.getRuntime();
        java.lang.Runtime runAgain=java.lang.Runtime.getRuntime();
        try
        {
            NoteWriter note=new NoteWriter();
            note.writeReceipt(orderCode,transferState,quantity);
            if(jCheckBox2.isSelected()){
                //run.exec("explorer C:\\Milliscript_MoneySpinner\\Note\\OfficialReceipt.htm");
                run.exec("explorer "+Configuration.officialReceiptPath);
            }
            //run.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\"C:\\Milliscript_MoneySpinner\\Note\\OfficialReceipt.htm\" ");
            run.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\""+Configuration.officialReceiptPath+"\" ");
        if(jCheckBox1.isSelected()){
            runAgain.exec("C:\\Program Files\\PrintHTML\\printhtml.exe file=\""+Configuration.officialReceiptPath+"\" ");
        }
            //printReceipt.setSelected(true);
        }
        catch(Exception e)
        {
            System.out.println("Error while adding edit employee ! "+e);
        }

        }
        refreshTable();    
    }
    
    private void disableControls()
    {
        jPrintReceiptButton.setEnabled(false);
        jPreviewReceiptButton.setEnabled(false);
        jRefreshButton.setEnabled(false);
        jCheckBox1.setEnabled(false);
        jCheckBox2.setEnabled(false);
    }                                             
    private void enableControls()
    {
        jPrintReceiptButton.setEnabled(true);
        jPreviewReceiptButton.setEnabled(true);
        jRefreshButton.setEnabled(true);
        jCheckBox1.setEnabled(true);
        jCheckBox2.setEnabled(true);
        this.setTitle("::. View Pending Credit Order Summary");
    }                 
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. View Pending Credit Order Summary - Processing Request");
            thread.sleep(500);
            this.setTitle("::. View Pending Credit Order Summary - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. View Pending Credit Order Summary - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. View Pending Credit Order Summary - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    public void refreshTable()
    {
        String[] departmentCode=systems.getTableDataArrayNum(OpenMSApp.Database_A,"vwPendingCreditOrder",1);
        String[] departmentName=systems.getTableDataArrayNum(OpenMSApp.Database_A,"vwPendingCreditOrder",3);

        int x=0;
        int y=departmentCode.length;

        tableObject=new Object[y][2];

        while(x<y)
        {
            tableObject[x][0]=departmentCode[x].trim();
            tableObject[x][1]=departmentName[x].trim();
            systems.freeHeap();
            x+=1;
            if(x==y){break;}
       }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Order Code", "Total Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        String firstValue="0";
        String secondValue="0";
        String sumValue="0";

            int a=tableObject.length;
            int b=0;
            while(b<a)
            {
                if(jTable1.getValueAt(b,1)!=null)
                {
                    firstValue=sumValue;
                    try
                    {
                        secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(b,1).toString());
                    }
                    catch(Exception e)
                    {
                        secondValue="Er!M1C01K0";
                    }
                    sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                    System.out.println(firstValue+" "+secondValue+" "+sumValue);
                }
                b+=1;
                if(b==a){break;}
            }
        try
        {
            jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
        }
        catch(Exception e)
        {
            jSumTextField.setText("Er!M1C01K0");
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCancelButton;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jPreviewReceiptButton;
    private javax.swing.JButton jPrintReceiptButton;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jSumTextField;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
